package org.jpass.dc.view.common;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;
import org.jpass.dc.business.user.bean.UserVOBean;
import org.jpass.dc.common.util.StringUtil;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class BasicAction extends ActionSupport {

	private static final long serialVersionUID = -7521893910523225533L;
	
	/**
	 * 取得应用程序的真实路径
	 * @return
	 */
	protected String getWebAppRealPath() {
		return StringUtil.formatPath(
				ServletActionContext.getServletContext().getRealPath("")); //取得应用程序上下文路径
	}
	/**
	 * 取得真实的应用程序上下文路径
	 * 
	 * @return
	 */
	protected String getUserRealWrokRootPath() {
		return StringUtil.formatPath(ServletActionContext.getServletContext().getRealPath(
				"/" + getUserWorkPath()));
	}

	/**
	 * 取得用户工作的根目录
	 * @return
	 */
	protected String getUserWorkPath() {
		return StringUtil.formatPath(this.getCurrentUser().getWorkPath());
	}
	
	/**
	 * 返回当前的用户
	 * @return
	 */
	protected UserVOBean getCurrentUser() {
		return(UserVOBean)ActionContext.getContext().getSession().get("user");
	}
	
	/**
	 * 取得系统的session
	 * @return
	 */
	protected Map<String, Object> getSession() {
		return ActionContext.getContext().getSession();
	}
	
	/**
	 * 取得系统的response
	 * @return
	 */
	protected HttpServletResponse getResponse() {
		return (HttpServletResponse) ActionContext.getContext()
					.get(ServletActionContext.HTTP_RESPONSE);
	}
	
	/**
	 * 取得系统的response
	 * @return
	 */
	protected HttpServletRequest getRequest() {
		return (HttpServletRequest) ActionContext.getContext()
					.get(ServletActionContext.HTTP_REQUEST);
	}
}
